package com.kly.likou.day01;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @author admin
 * @date 2025/4/18
 */
public class Demo1 {
    public static void main(String[] args) {
        int[] nums = {2, 7, 11, 15};
        int[] ints = new Demo1().twoSum(nums, 9);
    }


    public int[] twoSum(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<>();
        for(int i = 0; i < nums.length - 1; i++) {
            int num = nums[i];
            if(map.containsKey(num)) {
                return new int[]{map.get(num), i};
            }
            map.put(target - num, i);
        }
        return null;
    }

    public List<List<String>> groupAnagrams(String[] strs) {
        return new ArrayList<>(
                Arrays.stream(strs)
                        .collect(Collectors.groupingBy(s -> {
                            char[] chars = s.toCharArray();
                            Arrays.sort(chars);
                            return new String(chars);
                        })).values()
        );
    }
}
